$(function() {
var picServerPath = "http://img10.jiuxian.com/brandlogo/";
//创建右侧边栏
$('.page_slide_r').find('.ps_create input:eq(0)').click(
		function() {
			if ($('#adr').length > 0)
				return '';
			var str = '<div id="adr">' + '<div class="adr">'
					+ '<div class="ad_head"></div>'
					+ '<div class="ad_con"></div>' + '</div>'
					+ '<div r=0 class="ad_share">' + '<p>侧</p>' + '<p>边</p>'
					+ '<p>栏</p>' + '</div>' + '</div>';

			$('body').append(str);

		});
// 清除右侧边栏
$('.page_slide_r').find('.ps_create input:eq(1)').click(function() {
	$('#adr').remove();
});
// 创建左侧边栏
$('.page_slide_l').find('.ps_create input:eq(0)').click(
		function() {
			if ($('#adl').length > 0)
				return '';
			var str = '<div id="adl">' + '<div class="adl">'
					+ '<div class="ad_head"></div>'
					+ '<div class="ad_con"></div>' + '</div>'
					+ '<div l=0 class="ad_share">' + '<p>侧</p>' + '<p>边</p>'
					+ '<p>栏</p>' + '</div>' + '</div>';

			$('body').append(str);

		});
// 清除左侧边栏
$('.page_slide_l').find('.ps_create input:eq(1)').click(function() {
	$('#adl').remove();
});
/* 侧边栏end */
});


/* 侧边栏 */
function ad_SlideR() {
	var heightHeadR = $('.page_slide_r').find('.ps_head input').val();
	heightHeadR = heightHeadR || 100;
	var heightR = $('.page_slide_r').find('.ps_height input').val();
	heightR = heightR || 400;
	var strR = $('.page_slide_r').find('.ps_con textarea').val();


	$('.adr').find('.ad_head').css('height', heightHeadR);
	$('.adr').css('height', heightR);
	$('.adr').find('.ad_con').html(strR);
	$('.adr').find('.ad_share').css('margin-top', (heightR / 2 - 30) + 'px');
	
	var iScroll = document.documentElement.scrollTop || document.body.scrollTop;
	var h = ($(window).height() - parseInt($('.adr').css('height'))) / 2;
	var bStop = 0;
	var marginTop = parseInt($('.page_slide_r').find('.ps_height input').val())
			- parseInt($('.ad_share[r=0]').css('height'));
	$('#adr').css({
		'top' : iScroll + h + 'px'
	});
	$(window).bind('scroll', function() {
		$('#adr').stop().animate({
			'top' : $(document).scrollTop() + h + 'px'
		}, 300);
	});
	var rsideImg = $("#rsideImage").val();
	
	if(rsideImg!=''){
		$('.adr').css('background','url(' +picServerPath+rsideImg+')');
	}
	
	
	$('.ad_share[r=0]').css('margin-top', marginTop / 2 + 'px');
	$('.ad_share[r=0]').live('click', function() {
		if (!bStop) {
			$('.adr').stop().animate({
				'width' : '0px'
			}, 300);
			bStop = 1;
		} else {
			$('.adr').stop().animate({
				'width' : '170px'
			}, 300);
			bStop = 0;
		}
	});
	var content =document.getElementById('adr').outerHTML;
	//侧边栏类型
	var type = 1;
	$.ajax({
		type:"POST",
        url:"commonAjax.htm",
		data: {methodName:"newSide",headheight:heightHeadR,totalHeight:heightR,type:type,content:content,image:rsideImg,topicId:currentTopicId},
	    dataType: "json",
        async: false,
		success:function(data){
			if(data.code == 0){
			}else{alert("创建左侧边栏失败!");}
		},error:function(){
			alert("创建左侧边栏失败!");
		} 
	});
	
}
function ad_SlideL() {
	var heightHeadL = $('.page_slide_l').find('.ps_head input').val();
	heightHeadL = heightHeadL || 100;
	var heightL = $('.page_slide_l').find('.ps_height input').val();
	heightL = heightL || 400;
	var strL = $('.page_slide_l').find('.ps_con textarea').val();
	
	$('.adl').find('.ad_head').css('height', heightHeadL);
	$('.adl').css('height', heightL);
	$('.adl').find('.ad_con').html(strL);
	$('.adl').find('.ad_share').css('margin-top', (heightL / 2 - 30) + 'px');
	
	var iScroll = document.documentElement.scrollTop || document.body.scrollTop;
	var h = ($(window).height() - parseInt($('.adl').css('height'))) / 2;
	var bStop = 0;
	var marginTop = parseInt($('.page_slide_l').find('.ps_height input').val())
			- parseInt($('.ad_share[l=0]').css('height'));
	
	$('#adl').css({'top' : iScroll + h + 'px'});
	$(window).bind('scroll', function() {
		$('#adl').stop().animate({
			'top' : $(document).scrollTop() + h + 'px'
		}, 300);
	});
	var lsideImg = $("#lsideImage").val();
	if(lsideImg!=''){
		$('.adl').css('background','url(' +picServerPath+lsideImg+')');
	}
	$('.ad_share[l=0]').css('margin-top', marginTop / 2 + 'px');
	$('.ad_share[l=0]').live('click', function() {
		if (!bStop) {
			$('.adl').stop().animate({
				'width' : '0px'
			}, 300);
			bStop = 1;
		} else {
			$('.adl').stop().animate({
				'width' : '170px'
			}, 300);
			bStop = 0;
		}
	});
	
	var content = document.getElementById('adl').outerHTML;
	var type = 0;
	$.ajax({
		type:"POST",
        url:"commonAjax.htm",
		data: {methodName:"newSide",headheight:heightHeadL,totalHeight:heightL,type:type,content:content,image:lsideImg,topicId:currentTopicId},
	    dataType: "json",
        async: false,
		success:function(data){
			if(data.code == 0){
			}else{alert("创建左侧边栏失败!");}
		},error:function(){
			alert("创建左侧边栏失败!");
		} 
	});

	
};
